package com.ssy.lingxi.report.repository.settleaccount;

import com.ssy.lingxi.report.entity.settleaccount.PlatformScoreSettlementDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 平台积分结算
 * @author 伍将
 * @date 2020/12/14
 * @version 2.0.0
 */
public interface PlatformScoreSettlementRepository extends JpaRepository<PlatformScoreSettlementDO, Long>, JpaSpecificationExecutor<PlatformScoreSettlementDO> {

    @Query(value = "SELECT * FROM sa_platform_score_settlement " +
            " WHERE settlement_date=:settlementDate" +
            " AND member_id=:memberId AND role_id=:roleId" +
            " AND settlement_Way=:settlementWay", nativeQuery = true)
    PlatformScoreSettlementDO getDetail(Long settlementDate, Long memberId, Long roleId, Integer settlementWay);

    /**
     * 根据会员id、角色id获取大于等于数据id的积分结算数据并按照结算时间升序排序
     * @author 伍将
     * @date 2020/12/24
     * @param id:
     * @return:
     **/
    List<PlatformScoreSettlementDO> findAllByIdGreaterThanEqualAndMemberIdAndRoleIdOrderBySettlementDateAsc(Long id, Long memberId, Long roleId);

    /**
     * 批量删除结算数据
     * @param idList
     */
    @Transactional
    void deleteAllByIdIn(List<Long> idList);

}
